package com.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.entity.Detail;
import com.entity.Plan;
import com.service.DetailService;
import com.service.PlanService;

@Controller
public class DetailController {
@Resource
private DetailService detailService;
@Resource
private PlanService planService;
@RequestMapping("/getbyid")
public String getbyid(String pid){
	@SuppressWarnings("unused")
	List<Detail>list=detailService.getById(pid);
	return "update";
}
@RequestMapping("/detailadd")
public String detailadd(Detail detail){
	detailService.insert(detail);
	double dmoney=detailService.getsum(detail.getPid());
	Plan plan=new Plan();
	plan.setPid(detail.getPid());
	plan.setPcoutmoney(dmoney);
	planService.updateByPrimaryKeySelective(plan);
	return "redirect:/index?index=1";
}
@RequestMapping("/detailupdate")
public String detailupdate(Detail detail){
	detailService.updateByPrimaryKey(detail);
	double dmoney=detailService.getsum(detail.getPid());
	Plan plan=new Plan();
	plan.setPid(detail.getPid());
	plan.setPcoutmoney(dmoney);
	planService.updateByPrimaryKeySelective(plan);
	return "redirect:/index?index=1";
}
@RequestMapping("/detailgetBydid")
public String detailgetBydid(int did,Model model){
  Detail detail=detailService.selectByPrimaryKey(did);
  model.addAttribute("detail",detail);
	return "detailup";
}
@RequestMapping("/detaildelete")
public String detaildelete(int did,String pid){
	detailService.deleteByPrimaryKey(did);
	double dmoney=detailService.getsum(pid);
	Plan plan=new Plan();
	plan.setPid(pid);
	plan.setPcoutmoney(dmoney);
	planService.updateByPrimaryKeySelective(plan);
	return "redirect:/index?index=1";
}
}
